class Solution {
public:
    vector<int> postorder(Node* root) {
        vector<int> ans;
        if(!root){return ans;}
        stack<Node*> stk;
        Node* tmp;
        stk.push(root);
        while(!stk.empty()){
            tmp=stk.top();stk.pop();
            ans.push_back(tmp->val);
            for(int i=0;i<tmp->children.size();i++){
                stk.push(tmp->children[i]);
            }
        }
        reverse(ans.begin(),ans.end());
        return ans;
    }
};
